﻿class DragScreenButton {

	private var instance:MovieClip;
	private var dragClip:MovieClip;
	private var dragHiddenBnClip:MovieClip;
	public var dragBnBgLength:Number; //드래그 배경 총 길이를 의미

	//생성자 함수 초기화
	public function DragScreenButton(_instance:MovieClip, _dragClip:MovieClip, _dragHiddenBnClip:MovieClip,_dragBnBgLength:Number) {

		this.instance = _instance;
		this.dragClip = _dragClip;
		this.dragHiddenBnClip = _dragHiddenBnClip;
		this.dragBnBgLength = _dragBnBgLength;
		//
		this.buttonEvent();
	}

	private function buttonEvent():Void {

		var instance:MovieClip = this.instance;
		var dragClip:MovieClip = this.dragClip;
		var dragHiddenBnClip:MovieClip = this.dragHiddenBnClip;
		var dragBnBgLength:Number = this.dragBnBgLength;
		//
		dragClip.onPress = function() {
			instance.wheelCheck = false;
			this.startDrag(false,this._x,instance.dragIt.dragClipInitY,this._x,(instance.dragIt.dragClipInitY+dragBnBgLength-dragClip._height));
			instance.dragIt.dragControl();
		};
		//
		dragClip.onRelease = dragClip.onReleaseOutside=function () {
			this.stopDrag();
			delete instance.dragBarControl.onEnterFrame;
		};
		//
		dragHiddenBnClip.onRelease = function() {
			instance.wheelCheck = false;
			if (instance._ymouse<=instance.dragIt.dragClipInitY+dragBnBgLength-dragClip._height) {
				dragClip.targetYpos = instance._ymouse;
				trace(dragClip.targetYpos);
				
			} else {
				dragClip.targetYpos = instance.dragIt.dragClipInitY+dragBnBgLength-dragClip._height;
			}
			instance.dragIt.dragControl();
			instance.dragIt.dragMotionControl();
		};

	}
}